using Engine;
using Game;

namespace SCIENEW {
    public class BlastPortTransferrer : FluidTransferrer {
        public ComponentBlastFurnace m_componentBlastFurnace;

        public BlastPortTransferrer(Point3 position, SubsystemTerrain subsystemTerrain) : base(position, subsystemTerrain) { }

        public void AssignBlastFurnace(ComponentBlastFurnace componentBlastFurnace) {
            m_componentBlastFurnace = componentBlastFurnace;
        }

        public void ResetBlastFurnace() => m_componentBlastFurnace = null;

        public override ITank GetTank() => m_componentBlastFurnace;

        public override int RemoveFluid(ITank tank, float volume, out float removedVolume, out int removedTankIndex) {
            if (tank.GetTankVolume(0) <= 0) return base.RemoveFluid(tank, volume, out removedVolume, out removedTankIndex);
            if (tank is not ComponentBlastFurnace componentBlastFurnace) return base.RemoveFluid(tank, volume, out removedVolume, out removedTankIndex);
            if (!componentBlastFurnace.IsPortOpen) return base.RemoveFluid(tank, volume, out removedVolume, out removedTankIndex);

            int fluidValue = tank.GetTankValue(0);
            removedVolume = tank.RemoveTankFluid(0, volume);
            removedTankIndex = 0;
            return fluidValue;
        }
    }
}